﻿using System;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace EmailMarketingCampaign
{
    public partial class EditMessage : System.Web.UI.Page
    {
        Encoding code = Encoding.GetEncoding("utf-8");
        MessageControl mc = new MessageControl();
        CampaignControl cc = new CampaignControl();
        ScheduleControl sc = new ScheduleControl();

        protected void Page_Load(object sender, EventArgs e)
        {
            string body = "";

            if (!Page.IsPostBack)
            {
                if (Session["campaign"] != null)
                {

                    if (((Campaign)Session["campaign"]).getFrom().ToString() != "")
                    {
                        TxFrom.Text = ((Campaign)Session["campaign"]).getFrom().ToString();
                        TxSub.Text = ((Message)Session["message"]).getSubject().ToString();
                        body = ((Message)Session["message"]).getBody().ToString();
                        FCKeditor1.Value = body;
                    }
                    else
                    {
                        TxFrom.Text = "";
                        TxSub.Text = "";
                        body = ((Message)Session["message"]).getBody().ToString();
                        FCKeditor1.Value = body;

                    }
                }
            }

        }



        protected void btnNext_Click(object sender, EventArgs e)
        {

            string subject = TxSub.Text.ToString();
            string body = FCKeditor1.Value.ToString();
            string from = TxFrom.Text.ToString();
            mc.updateEmailByCampaignID(subject, body, ((Campaign)Session["campaign"]));
            cc.updateCampaignFrom(from, ((Campaign)Session["campaign"]));

            ((Campaign)Session["campaign"]).setFrom(from);
            ((Message)Session["message"]).setSubject(subject);
            ((Message)Session["message"]).setBody(body);

            Response.Redirect("MemberSelect.aspx");

        }
        protected void btnSave_Click(object sender, EventArgs e)
        {


            string subject = TxSub.Text.ToString();
            string body = FCKeditor1.Value.ToString();
            string from = TxFrom.Text.ToString();
            mc.updateEmailByCampaignID(subject, body, ((Campaign)Session["campaign"]));
            cc.updateCampaignFrom(from, ((Campaign)Session["campaign"]));

            this.Response.Write(" <script>alert('Please select at least one request.'); </script>");

        }


        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("TypeofMessage.aspx");
        }
        protected void btnSend_Click(object sender, EventArgs e)
        {
            string Subject = TxSub.Text.ToString();
            string Body = FCKeditor1.Value;
            string from = TxFrom.Text.ToString();

            //sc.sendMails(from,"", Subject, Body);

            this.Response.Write(" <script>alert('Sent Successfully.'); </script>");
        }

    }
}
